﻿using JianZhangTool.config;
using JianZhangTool.tool;
using System;
using System.Windows.Forms;

namespace JianZhangTool.menu
{
    public partial class ShenyuanParams : Form
    {
        public ShenyuanParams()
        {
            InitializeComponent();
            InitText();
        }

        private void InitText()
        {
            param_3_textbox.Text = StaticConfig.jianzhang_shenyuan_param + "";
            param_2_textbox.Text = StaticConfig.tidu_shenyuan_param + "";
            param_1_textbox.Text = StaticConfig.zongdu_shenyuan_param + "";
        }

        /// <summary>
        /// 确认修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void confirm_button_Click(object sender, System.EventArgs e)
        {
            try
            {
                int jzp = int.Parse(param_3_textbox.Text);
                int tdp = int.Parse(param_2_textbox.Text);
                int zdp = int.Parse(param_1_textbox.Text);
                bool change = false;
                if (StaticConfig.jianzhang_shenyuan_param != jzp)
                {
                    StaticConfig.jianzhang_shenyuan_param = jzp;
                    change = true;
                }
                if (StaticConfig.tidu_shenyuan_param != tdp)
                {
                    StaticConfig.tidu_shenyuan_param = tdp;
                    change = true;
                }
                if (StaticConfig.zongdu_shenyuan_param != zdp)
                {
                    StaticConfig.zongdu_shenyuan_param = zdp;
                    change = true;
                }
                if (change)
                {
                    StaticConfig.Save();
                }
                Tools.alert_message("成功", "参数修改成功!");
                Close();
            }
            catch (Exception)
            {
                Tools.alert_message("错误", "参数格式错误");
            }
        }

        /// <summary>
        /// 回退
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void quit_button_Click(object sender, EventArgs e)
        {
            Close();
        }
    }
}
